package nicg.st.service.generatereportservice;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Stack;

import nicg.st.entity.Divate;
import nicg.st.entity.EvalResult;
import nicg.st.entity.IndicatorTree;

public abstract class BaseReport {

	final String[] numberString1 = { "严重", "较大", "一般", "较少" };
	final String[] numberString2 = { "较少", "一般", "较大", "严重" };
	final String[] degreeString = { "较差", "一般", "良好", "优秀" };

	// 下面一行是实现类需要实现的抽象方法
	public String produceSelfReport(EvalResult evalResult, IndicatorTree itNode, List<Divate> divateList) {
		return "";
	}

	// 从这下面开始有3个默认方法，供子类使用或者复写
	public String[] produceBaseReport(EvalResult evalResult, IndicatorTree itNode) {
		double ourPersonDamage = 0, ourEquipDamage = 0, ourTargetDamage = 0;
		double enemyPersonDamage = 0, enemyEquipDamage = 0, enemyTargetDamage = 0;

		SimpleDateFormat sdf = new SimpleDateFormat("yyy年MM月dd日 hh:mm:ss");
		String dateString = sdf.format(new Date());

		String[] report = new String[3];

		report[0] = "截止时间" + dateString + "，当前任务完成度" + evalResult.getCompletion() + "%，计划偏离度"
				+ evalResult.getDeviate().size() + "，作战综合效果评估分数" + evalResult.getScore() + "分， 详情如下：<br/>";

		Stack<IndicatorTree> stack = new Stack<>();
		stack.push(itNode);
		while (!stack.isEmpty()) {
			IndicatorTree nowNode = stack.pop();
			if (nowNode.getName().equals("本单位人员伤亡情况"))
				ourPersonDamage = nowNode.getValue2();
			if (nowNode.getName().equals("本单位装备毁伤情况"))
				ourEquipDamage = nowNode.getValue2();
			if (nowNode.getName().equals("本单位关键目标被摧毁情况"))
				ourTargetDamage = nowNode.getValue2();
			if (nowNode.getName().equals("目标敌人员伤亡情况"))
				enemyPersonDamage = nowNode.getValue2();
			if (nowNode.getName().equals("目标敌装备毁伤情况"))
				enemyEquipDamage = nowNode.getValue2();
			if (nowNode.getName().equals("目标敌关键目标摧毁情况"))
				enemyTargetDamage = nowNode.getValue2();

			List<IndicatorTree> children = nowNode.getChildren();
			if (children != null) {
				for (IndicatorTree child : children) {
					stack.push(child);
				}
			}
		}

		report[1] = "1.战损<br/>我方人员伤亡" + numberString1[genrateString(ourPersonDamage)] + "，装备毁伤"
				+ numberString1[genrateString(ourEquipDamage)] + "，我方设施损毁情况"
				+ numberString1[genrateString(ourTargetDamage)] + "。<br/>";
		report[2] = "2.战果<br/>敌方人员伤亡" + numberString2[genrateString(enemyPersonDamage)] + "，装备毁伤"
				+ numberString2[genrateString(enemyEquipDamage)] + "，敌方设施损毁情况"
				+ numberString2[genrateString(enemyTargetDamage)] + "。<br/>";

		return report;
	}

	public int genrateString(double score) {
		if (score < 60)
			return 0;
		if (score < 70)
			return 1;
		if (score < 90)
			return 2;
		else
			return 3;
	}

	public String produceDivateReport(EvalResult evalResult, List<Divate> divateList, int seq) {
		String divateReport = null;
		if (evalResult.getDeviate().size() > 0) {
			divateReport = seq + ".偏离<br/>和作战计划偏离严重的问题有：" + "<br/>";
			for (int i = 0; i < evalResult.getDeviate().size(); i++) {
				for (Divate temp : divateList) {
					if (evalResult.getDeviate().get(i).equals(temp.getDivateName())) {
						divateReport += "（" + seq + "）" + temp.getDivateDiscribe() + "<br/>";
						seq++;
					}
				}
			}
		}
		return divateReport;
	}
}
